package at.fhj.itm11.forum.gui;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;

import at.fhj.itm11.forum.api.ApiLookupNames;
import at.fhj.itm11.forum.service.TestHelperService;

public class US06 extends AbstractGUITest {
	 private TestHelperService dbHelper;
	 
  private boolean acceptNextAlert = true;
  
  @Before
  public void additionalSetUp() {
		dbHelper = lookupBean(ApiLookupNames.TEST_HELPER,
				TestHelperService.class);

		dbHelper.cleanDB();
		dbHelper.createDemoData();
  }

  @Test
  public void happyPathTestShowPosts() throws Exception {

	navigateToBasePage();
    driver.findElement(By.linkText("DemoThema")).click();
    assertEquals("DemoBeitrag", driver.findElement(By.xpath("/html/body/div/div/div/form/table/tbody/tr/td/div/div/span")).getText());
    assertEquals("DemoBeitrag2", driver.findElement(By.xpath("/html/body/div/div/div/form/table/tbody/tr[4]/td/div/div/span")).getText());
    assertTrue(isElementPresent(By.xpath("/html/body/div/div/div/form/table/tbody/tr/td/div/div[2]/img")));
  }


  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }


}
